//
//  WCNTabBarController.m
//  WCN
//
//  Created by 杨鑫 on 15/5/29.
//  Copyright (c) 2015年 ShanghaiCize Trade And Business Co., Ltd. All rights reserved.
//

#import "HELTabBarVC.h"
#import "WSJTabarStaticData.h"
#import "SQTabbarControllerAnimatedTransitioning.h"
#import "HELHomeVC.h"
#import "HELPersonVC.h"
#import "HELNavigationContrller.h"
#import "HELLoginVC.h"

//----------
//两次提示的默认间隔
//static const CGFloat kDefaultPlaySoundInterval = 3.0;
static NSString *kMessageType = @"MessageType";
static NSString *kConversationChatter = @"ConversationChatter";
static NSString *kGroupName = @"GroupName";
@interface HELTabBarVC () <UITabBarControllerDelegate>

    

@property (strong, nonatomic) NSDate *lastPlaySoundDate;


@end

@implementation HELTabBarVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.delegate = self;
    HELHomeVC *helHomeVC =[HELHomeVC new];
    HELPersonVC *personVC = [[HELPersonVC alloc] init];
    
    self.viewControllers = @[helHomeVC, personVC];
    
    helHomeVC.tabBarItem.title = @"学习资料";
    helHomeVC.tabBarItem.image = [[UIImage imageNamed:@"资料"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
;
    helHomeVC.tabBarItem.selectedImage =[[UIImage imageNamed:@"资料选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
;
    helHomeVC.view.backgroundColor = [UIColor redColor];
    personVC.tabBarItem.title = @"个人";
    personVC.tabBarItem.image =  [UIImage imageNamed:@"个人"];
    personVC.tabBarItem.selectedImage = [[UIImage imageNamed:@"个人选中"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    UITabBar *tarBar = self.tabBar;
    tarBar.translucent = NO;
    tarBar.barTintColor = [UIColor whiteColor];
    
    for (UITabBarItem *item in tarBar.items) {
        
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor grayColor]} forState:UIControlStateNormal];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName: kMainColor} forState:UIControlStateSelected];
    }
    
}


#pragma mark - Setter

- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    [super setSelectedIndex:selectedIndex];
    _tab_selectedIndex = selectedIndex;
    
    [self tabBarController:self didSelectViewController:self.viewControllers[selectedIndex]];
}

- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    
//    [item setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:10.0f],
//                                                        NSForegroundColorAttributeName : [UIColor purpleColor]
//                                                        } forState:UIControlStateSelected];

}
#pragma mark - UITabBarControllerDelegate
// 当前控制的导航栏项元素
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
    self.navigationItem.titleView = viewController.navigationItem.titleView;
    self.navigationItem.leftBarButtonItems = viewController.navigationItem.leftBarButtonItems;
    self.navigationItem.rightBarButtonItems = viewController.navigationItem.rightBarButtonItems;
}
- (void)showBadageOnItem:(NSInteger)index
{
    
    UITabBarItem *item =  self.tabBar.items[index];
    item.badgeValue  =@"new";
    
}


- (id <UIViewControllerAnimatedTransitioning>)tabBarController:(UITabBarController *)tabBarController animationControllerForTransitionFromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC {
    
    _tab_preIndex = [self.viewControllers indexOfObject:fromVC];
    _tab_selectedIndex =[self.viewControllers indexOfObject:toVC];
    
    return [SQTabbarControllerAnimatedTransitioning new];
}


@end
